/*
 * Copyright (C) 2017-2025
 * All rights reserved, Designed By 深圳中科鑫智科技有限公司
 * Copyright authorization contact 18814114118
 */
package com.shop.zkmall.business;

import com.shop.zkmall.business.service.common.CommonService;
import com.shop.zkmall.business.service.redis.CereRedisKeyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableAsync
@SpringBootApplication(scanBasePackages = {"com.shop.zkmall.commons.utils", "com.shop.zkmall.business", "com.shop.zkmall.commons.config"})
public class CereshopBusinessApplication extends SpringBootServletInitializer implements CommandLineRunner {


    @Autowired
    private CereRedisKeyService cereRedisKeyService;

    @Autowired
    private CommonService commonService;

    /**
     * 需要把web项目打成war包部署到外部tomcat运行时需要改变启动方式
     */
    @Override  //重写configure方法，把springboot的入口给它
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(CereshopBusinessApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(CereshopBusinessApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        //        //开启运营计划定时任务
//        TimingTask timingTask=new TimingTask();
//        //运营计划定时任务筛选出满足人群的新增客户并发送消息通知和发放优惠券
//        ScheduledFuture<?> operateFuture = timingTask.startExtensionInitialization("0 0 0 * * ?",
//                new OperateInitializationRunnable(cereShopOperateService, cereShopCouponService));
//        //定时任务轮训所有规格库存为0的商品改为已下架状态
//        ScheduledFuture<?> productDown = timingTask.startProductDownInitialization("0 0 0 * * ?",
//                new ProductDownRunnable(cereShopProductService));
//        //定时任务轮训所有人群,重新筛选当前最新满足条件的客户数据
//        ScheduledFuture<?> crowdPerson = timingTask.startUpdateCrowdPersonInitialization("0 0 0 * * ?",
//                new UpdateCrowdPersonRunnable(cereShopCrowdService));
//        //开启营销活动状态补偿修改定时任务
//        ScheduledFuture<?> tool = timingTask.startToolUpdateInitialization("0 0 0 * * ?",
//                new ToolRunnable(commonService));
////        //定时任务轮训所有场景营销活动,更新状态(无用)
////        ScheduledFuture<?> scene = timingTask.startUpdateCrowdPersonInitialization("0 0 0 * * ?",
////                new UpdateCrowdPersonRunnable(cereShopCrowdService));
        try {
            //初始化Redis延时任务
            cereRedisKeyService.initializationRedis();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.out.println("------   business-server启动成功    ------\n");
        }
    }
}
